package com.bootdo.program.shejiao.controller;

import java.util.List;
import java.util.Map;

import com.bootdo.common.config.Constant;
import com.bootdo.common.controller.BaseController;
import com.bootdo.program.shejiao.service.MSaveNoteService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bootdo.program.shejiao.domain.MSaveNoteDO;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;

/**
 * 存纸条表
 * 
 * @author guoyunfei
 * @email 2549789059@qq.com
 * @date 2021-10-11 10:42:40
 */
 
@Controller
@RequestMapping("/shejiao/mSaveNote")
public class MSaveNoteController extends BaseController {
	@Autowired
	private MSaveNoteService mSaveNoteService;
	
	@GetMapping()
	@RequiresPermissions("shejiao:mSaveNote:mSaveNote")
	String MSaveNote(){
	    return "shejiao/mSaveNote/mSaveNote";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("shejiao:mSaveNote:mSaveNote")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		//query.put("delFlag",1);
		query.put("appid",queryAppid());
		List<MSaveNoteDO> mSaveNoteList = mSaveNoteService.list(query);
		int total = mSaveNoteService.count(query);
		PageUtils pageUtils = new PageUtils(mSaveNoteList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("shejiao:mSaveNote:add")
	String add(){
	    return "shejiao/mSaveNote/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("shejiao:mSaveNote:edit")
	String edit(@PathVariable("id") Long id,Model model){

		MSaveNoteDO mSaveNote = mSaveNoteService.get(id);
		model.addAttribute("mSaveNote", mSaveNote);
	    return "shejiao/mSaveNote/edit";
	}

	@GetMapping("/edit2/{id}")
	@RequiresPermissions("shejiao:mSaveNote:edit")
	String edit2(@PathVariable("id") Long id,Model model){

		MSaveNoteDO mSaveNote = mSaveNoteService.get(id);
		model.addAttribute("mSaveNote", mSaveNote);
		return "shejiao/mSaveNote/edit2";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("shejiao:mSaveNote:add")
	public R save( MSaveNoteDO mSaveNote){
		String message = getMessage();
		if(null != message){
			return R.error(message);
		}
		mSaveNote.setDelFlag(1);
		mSaveNote.setStatus(2);
		mSaveNote.setAppid(getAppid());
		if(mSaveNoteService.save(mSaveNote)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("shejiao:mSaveNote:edit")
	public R update( MSaveNoteDO mSaveNote){
		String message = getMessage();
		if(null != message){
			return R.error(message);
		}
		mSaveNote.setAppid(getAppid());
		mSaveNote.setDelFlag(1);
		mSaveNoteService.update(mSaveNote);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("shejiao:mSaveNote:remove")
	public R remove( Long id){
		String message = getMessage();
		if(null != message){
			return R.error(message);
		}
		MSaveNoteDO noteDO = mSaveNoteService.get(id);
		noteDO.setDelFlag(0);
		if(mSaveNoteService.update(noteDO) > 0){
			return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("shejiao:mSaveNote:batchRemove")
	public R remove(@RequestParam("ids[]") Long[] ids){
		String message = getMessage();
		if(null != message){
			return R.error(message);
		}
		mSaveNoteService.batchRemove(ids);
		return R.ok();
	}
	
}
